package org.light.simpleauth;

import java.util.ArrayList;
import java.util.List;

import org.light.core.Writeable;
import org.light.domain.Domain;
import org.light.domain.Statement;
import org.light.domain.Util;
import org.light.utils.DomainUtil;
import org.light.utils.WriteableUtil;

public class IndexControllerGenerator extends Util{
	protected Domain userDomain;
	
	public IndexControllerGenerator(Domain userDoamin){
		super();
		this.userDomain = userDoamin;
		super.fileName = "Index"+this.userDomain.getControllerNamingSuffix()+".go";
	}

	@Override
	public String generateUtilString() throws Exception{
		List<Writeable> sList = new ArrayList<Writeable>();
		sList.add(new Statement(1000L,0,"package "+DomainUtil.genPackagetokenWithPackage(this.userDomain.getPackageToken(),this.userDomain.getControllerSuffix())));
		sList.add(new Statement(2000L,0,""));
		
		sList.add(new Statement(3000L,0,"import ("));
		sList.add(new Statement(4000L,1,"session \"github.com/ScottHuangZL/gin-jwt-session\""));
		sList.add(new Statement(5000L,1,"\"github.com/gin-gonic/gin\""));
		sList.add(new Statement(10000L,0,")"));
		sList.add(new Statement(11000L,0,""));
		sList.add(new Statement(12000L,0,"func LoginIndex(c *gin.Context) {"));
		sList.add(new Statement(13000L,1,"session.GetFlashes(c)"));
		sList.add(new Statement(14000L,1,"session.DeleteAllSession(c)"));
		sList.add(new Statement(15000L,1,"SendResponse(c, nil, nil, 0, true)"));
		sList.add(new Statement(16000L,0,"}"));
		sList.add(new Statement(17000L,0,""));
		sList.add(new Statement(18000L,0,"func HomeIndex(c *gin.Context) {"));
		sList.add(new Statement(19000L,1,"SendResponse(c, nil, nil, 0, true)"));
		sList.add(new Statement(20000L,0,"}"));

		return WriteableUtil.merge(sList).getContent();
	}

	public Domain getUserDomain() {
		return userDomain;
	}

	public void setUserDomain(Domain userDomain) {
		this.userDomain = userDomain;
	}


}
